var sourceType = [['camera'], ['album'], ['camera', 'album']]
var sizeType = [['compressed'], ['original'], ['compressed', 'original']]
var app = getApp();
var aa = [];
Page({
  data: {
    star: 0,
    starMap: [
      '非常差',
      '差',
      '一般',
      '好',
      '非常好',
    ],
    star2: 0,
    starMap2: [
      '非常差',
      '差',
      '一般',
      '好',
      '非常好',
    ],
    star3: 0,
    starMap3: [
      '非常差',
      '差',
      '一般',
      '好',
      '非常好',
    ],
    star4: 0,
    starMap4: [
      '非常差',
      '差',
      '一般',
      '好',
      '非常好',
    ],
    sourceTypeIndex: 2,
    sourceType: ['拍照', '相册', '拍照或相册'],

    sizeTypeIndex: 0,
    sizeType: ['压缩', '原图', '压缩或原图'],

    countIndex: 2,
    count: [1, 2, 3, 4, 5, 6, 7, 8, 9]
  },
  myStarChoose(e) {
    var indexs = e.currentTarget.dataset.index;
    let star = parseInt(e.target.dataset.star) || 0;  //5
    
    var xx = this.data.comment;
    xx[indexs].star = star;

    this.setData({
      comment: xx,
    });
  },

  myStarChoose2(e) {
    let star2 = parseInt(e.target.dataset.star) || 0;
    this.setData({
      star2: star2,
    });
  },
  myStarChoose3(e) {
    let star3 = parseInt(e.target.dataset.star) || 0;
    this.setData({
      star3: star3,
    });
  },
  myStarChoose4(e) {
    let star4 = parseInt(e.target.dataset.star) || 0;
    this.setData({
      star4: star4,
    });
  },
  sourceTypeChange: function (e) {
    this.setData({
      sourceTypeIndex: e.detail.value
    })
  },
  sizeTypeChange: function (e) {
    this.setData({
      sizeTypeIndex: e.detail.value
    })
  },
  countChange: function (e) {
    this.setData({
      countIndex: e.detail.value
    })
  },

  onLoad:function(option){
    var ide = option.ide;
    var that = this;
    wx.request({
      url: 'https://www.cakeyouxuan.com/small/order/comment',
      data: {
        id: ide,
      },
      method: "POST",
      header: {
        "Content-Type": "application/x-www-form-urlencoded"  //post
      },
      success: function (res) {
        console.log(res);
       that.setData({
         comment: res.data.comment,
       })
      },
    })
  },
  bacred:function(){
    wx.navigateTo({
      url: '/pages/yiguo/record/record',
    })
  },
  chooseImage: function (e) {//这里是选取图片的方法
    var that = this;
    var index = e.currentTarget.dataset.index;
    var comment = that.data.comment;
    wx.chooseImage({
      //count: 9 - pic.length, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function (res) {
        var imgsrc = res.tempFilePaths;
        comment[index].imageList = imgsrc;
        that.setData({
          comment: comment,
        });
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })

  },

  //获取评论框的值
  bindKeyInput:function(e){
    let index = e.currentTarget.dataset.index;
    this.data.comment[index].input_text = e.detail.value;  
  },

  previewImage: function (e) {
    var current = e.target.dataset.src

    wx.previewImage({
      current: current,
      urls: this.data.imageList
    })
  },
  
//form提交
  formSubmit:function(e){
    var comment = this.data.comment;
    var comment1 = JSON.stringify(comment);
    var uid = app.whereId.uid;
    var fen1 = e.detail.value.fen1;
    var fen2 = e.detail.value.fen2;
    var fen3 = e.detail.value.fen3;
    var shopid = app.whereId.shopid;
      wx.request({
        url: 'https://www.cakeyouxuan.com/small/comment/comment_add',
        data: {
          comment: comment1,
          uid: uid,
          fen1: fen1,
          fen2: fen2,
          fen3: fen3,
          shopid: shopid,
        },
        method: "POST",
        header: {
          "Content-Type": "application/x-www-form-urlencoded"  //post
        },
        success: function (res) {
          if (res.data.msg == 'T') {
            wx.showToast({
              title: '评论成功',
              duration: 1000,
              success: function () {
                setTimeout(function () {
                  //要延时执行的代码
                  wx.navigateTo({
                    url: "/pages/yiguo/mine/mine",
                  })
                }, 1000) //延迟时间 
              }
            });
          }
        },
      })
  },

});